package com.matt.controller.web.course;

import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.ErrorCode;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.foundation.vo.BindedBabyVO;
import com.starinside.wp.service.BindedBabyService;
import com.starinside.wp.service.TeachAPICallService;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.starinside.wp.foundation.constant.RequestConstant.TICKET;

@RestController
@Api(tags = "托班课表")
@RequestMapping(value = "/web/nursery_schedule")
public class WebNurseryScheduleController {

    @Autowired
    TeachAPICallService teachAPICallService;

    @Autowired
    BindedBabyService bindedBabyService;

    //托班排课列表
    @ApiOperation(value = "当前宝宝的课表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "formData", name = "beginDate", value = "开始日期：yyyy-MM-dd", required = true, dataType = "string"),
//            @ApiImplicitParam(paramType = "formData", name = "endDate", value = "结束日期：yyyy-MM-dd", required = true, dataType = "string"),
//    })
//    @ApiResponses({
//		@ApiResponse(code = 000000, message = "成功"),
//		@ApiResponse(code = 000001, message = "ticket已过期")
//	})
    @GetMapping(value = "/list")
    public StatusResponse scheduleList(HttpServletRequest req,
                                       @RequestHeader(TICKET) String ticket,
                                       String courseDateStr) {

        WxUser user = (WxUser) req.getSession().getAttribute("loginUser");

        if (StringUtils.isEmpty(user.getDefaultBabyId())){
            return StatusResponse.error(ErrorCode.CHILDREN_STATUS_ERROR, "没有选择默认宝宝");
        }

        BindedBabyVO defaultBaby = bindedBabyService.getBindedBaby(user.getDefaultBabyId(), user.getParentMobile());

        String classIdsStr = defaultBaby.getClassIds();

        if (StringUtils.isBlank(classIdsStr)){
            return StatusResponse.error(ErrorCode.CHILDREN_STATUS_ERROR, "宝宝没有班级");
        }

        String[] classIds = classIdsStr.split(",");

        return StatusResponse.success(teachAPICallService.getNurseryScheduler( classIds[0], courseDateStr));
    }
}
